#include <cstdio>
#include <algorithm>
using namespace std; 
const int maxn = 111111;
int h , w , n;
int col[maxn<<2];
int sum[maxn<<2];
void PushUp(int u) 
{
	sum[u] = sum[u*2] + sum[u*2+1];
}
void PushDown(int u,int m) 
{
	if(col[u]) 
	{
		col[u*2] = col[u*2+1] = col[u];
		sum[u*2] = (m-(m >> 1)) * col[u];
		sum[u*2+1] = (m >> 1) * col[u];
		col[u] = 0;
	}
}
void build(int l,int r,int u) 
{
	col[u] = 0;
	sum[u] =1;
	if(l==r)return;
	int mid=(l+r)>>1;
	build(l,mid,u*2);
	build(mid+1,r,u*2+1);
	PushUp(u);
}
void update(int L,int R,int c,int l,int r,int rt) 
{
	if (L<=l&&r<=R) 
	{
		col[rt]=c;
		sum[rt]=c*(r-l+1);
		return ;
	}
	PushDown(rt,r-l+1);
	int mid=(l+r)/2;
	if (L<=m)update(L,R,c,l,mid,u*2);
	if (R>m)update(L,R,c,mid+1,r,u*2+1);
	PushUp(rt);
}
int main() 
{
	int T,n,m;
	scanf("%d",&T);
	for (int cas = 1;cas<=T;cas++) 
	{
		scanf("%d%d",&n,&m);
		build(1,n,1);
		while (m --)
		{
			int a,b,c;
			scanf("%d%d%d",&a,&b,&c);
			update(a,b,c,1,n,1);
		}
		printf("Case %d: The total value of the hook is %d.\n",cas , sum[1]);
	}
	return 0;
}

